use std::collections::HashMap;

use derive_builder::Builder;
use serde::{Deserialize, Serialize};

use crate::error::Error;

// TTS Text-To-Speech
// SV2TTS Transfer Learning from Speaker Verification to Multispeaker Text-To-Speech Synthesis
// ASR Automatic Speech Recognition
#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub enum AssistantAbility {
    #[default]
    Chat,
    SV2TTS,
    SADTALKER,
    TTS,
    ASR,
    HTTP,
    SHELL,
    Unkown,
}

impl TryFrom<String> for AssistantAbility {
    type Error = anyhow::Error;

    fn try_from(value: String) -> Result<Self, Self::Error> {
        if value.to_uppercase() == "CHAT" {
            return Ok(AssistantAbility::Chat);
        } else if value.to_uppercase() == "SV2TTS" {
            return Ok(AssistantAbility::SV2TTS);
        } else if value.to_uppercase() == "SADTALKER" {
            return Ok(AssistantAbility::SADTALKER);
        } else if value.to_uppercase() == "HTTP" {
            return Ok(AssistantAbility::HTTP);
        } else if value.to_uppercase() == "SHELL" {
            return Ok(AssistantAbility::SHELL);
        } else if value.to_uppercase() == "TTS" {
            return Ok(AssistantAbility::TTS);
        } else if value.to_uppercase() == "ASR" {
            return Ok(AssistantAbility::ASR);
        }
        Ok(AssistantAbility::Unkown)
    }
}

impl TryInto<String> for AssistantAbility {
    type Error = anyhow::Error;

    fn try_into(self) -> Result<String, Self::Error> {
        match self {
            AssistantAbility::Chat => Ok(String::from("CHAT")),
            AssistantAbility::TTS => Ok(String::from("TTS")),
            AssistantAbility::SV2TTS => Ok(String::from("SV2TTS")),
            AssistantAbility::SADTALKER => Ok(String::from("SADTALKER")),
            AssistantAbility::SHELL => Ok(String::from("SHELL")),
            AssistantAbility::HTTP => Ok(String::from("HTTP")),
            AssistantAbility::ASR => Ok(String::from("ASR")),
            AssistantAbility::Unkown => Ok(String::from("UNKOWN")),
            _ => Err(anyhow::anyhow!("")),
        }
    }
}
